java 将"a.b.c.d"中的点符号转换成反斜杠

来源:百度知道 编辑:UC知道 时间:2024/05/27 12:20:22
"a.b.c.d".replaceAll("\\.", "\\");
这样写为什么会抛出 java.lang.StringIndexOutOfBoundsException

System.out.println("a.b.c.d".replaceAll("[.]", "/"));
不知道为什么好象不能用\\或者\
有待思考

String str = "a.b.c.d";
str = str.replaceAll(".", "/");
System.out.println(str);

String str = "a.b.c.d";
str = str.replaceAll(".","\\\\");
System.out.println(str);
为什么要4个\才可以啊,

String s = "a.b.c.d";
String result = s.replaceAll("\\.", "\\\\");
System.out.println(result);

"a.b.c.d".replaceAll("[.]", "[\\]");

System.out.println("a.b.c.d".replaceAll("\\.","\\\\"));